package org.xw.controller;

import jakarta.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.xw.dto.UserDto;
import org.xw.service.SearchService;
import org.xw.utils.ResponseUtil;

import java.util.HashMap;

@RestController
@RequestMapping("/search")
public class SearchController {
    @Autowired
    SearchService service;

    @GetMapping("")
    public ResponseUtil search(String content, HttpServletRequest request) {
        HashMap search = service.search(content, request);
        if (search != null || !search.isEmpty()) {
            return ResponseUtil.success(search);
        } else return ResponseUtil.error("未查询到数据!");
    }

    @GetMapping("/user")
    public ResponseUtil searchUser(String phone, HttpServletRequest request){
        UserDto userDto = service.searchUserByPhone(phone, request);
        if (userDto!=null){
            return ResponseUtil.success(userDto);
        }else return ResponseUtil.error("暂无信息");
    }
}
